import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet("/Attribute")
public class GetAttribute extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StringBuilder stringBuilder = new StringBuilder();
        resp.setContentType("text/html; charset=utf8");
        stringBuilder.append("UrL:").append(req.getRequestURL());
        stringBuilder.append("<br>");
        stringBuilder.append("method: ").append(req.getMethod());
        stringBuilder.append("<br>");
        stringBuilder.append("protocol: ").append(req.getProtocol());
        stringBuilder.append("<br>");
        stringBuilder.append("query string: ").append(req.getQueryString());
        stringBuilder.append("<br>");
        stringBuilder.append("content path: ").append(req.getContextPath());
        stringBuilder.append("<br>");
        Enumeration<String> headers = req.getHeaderNames();
        while (headers.hasMoreElements()) {
            String headName = headers.nextElement();
            stringBuilder.append(headName).append(" ").append(req.getHeader(headName));
            stringBuilder.append("<br>");
        }
        PrintWriter writer = resp.getWriter();
        writer.write(stringBuilder.toString());
        writer.flush();
    }
}
